<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
    <meta name="screen-orientation" content="portrait"/>
    <meta name="apple-mobile-web-app-capable" content="no">
    <meta name="format-detection" content="telephone=no">
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <!-- 缓存清除 -->
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache,no-store">
    <meta http-equiv="Expires" content="0">
    <meta name="referrer" content="unsafe-url">
    <link src="https://img.fphdcdn.com/hall/test/layer.css"/>
    <title>支付中心</title>
    <script src="/config.js"></script>
    <style type="text/css">
        a,
        article,
        aside,
        b,
        body,
        button,
        dd,
        div,
        dl,
        dt,
        figcaption,
        figure,
        footer,
        h1,
        h2,
        h3,
        h4,
        h5,
        h6,
        header,
        i,
        input,
        li,
        nav,
        p,
        section,
        select,
        span,
        textarea,
        ul {
            padding: 0;
            margin: 0;
            list-style: none;
            font-style: normal;
            text-decoration: none;
            border: 0;
            font-weight: 400;
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
            -webkit-font-smoothing: antialiased
        }

        a:hover,
        article:hover,
        aside:hover,
        b:hover,
        body:hover,
        button:hover,
        dd:hover,
        div:hover,
        dl:hover,
        dt:hover,
        figcaption:hover,
        figure:hover,
        footer:hover,
        h1:hover,
        h2:hover,
        h3:hover,
        h4:hover,
        h5:hover,
        h6:hover,
        header:hover,
        i:hover,
        input:hover,
        li:hover,
        nav:hover,
        p:hover,
        section:hover,
        select:hover,
        span:hover,
        textarea:hover,
        ul:hover {
            outline: 0
        }


        a {
            background-color: transparent;
            color: #333
        }

        * {
            box-sizing: border-box
        }

        body,
        html {
            width: 100%
        }

        body {
            margin: 0 auto;
            box-sizing: border-box;
            width: 100%;
            text-align: center;
            margin: 0;
            background: #f7f7f7;
            -webkit-text-size-adjust: 100% !important;
            text-size-adjust: 100% !important;
            -moz-text-size-adjust: 100% !important
        }

        body input,
        body button,
        body select,
        body textarea {
            outline: 0
        }

        body a {
            text-decoration: none
        }

        body img {
            width: 100%
        }

        body ul {
            padding: 0;
            margin: 0;
            list-style: none
        }

        body .df {
            display: flex;
            display: -webkit-flex
        }

        body .absolute {
            position: absolute
        }

        body .relative {
            position: relative
        }

        p {
            margin: 0
        }

        .user_data {
            background: white;
            padding: 1.2rem .6rem .8rem .6rem
        }

        .top {
            border-bottom: .02rem solid #e0e0e0;
            justify-content: space-between;
            align-items: center;
            padding: .52rem 0
        }

        .top b {
            display: block;
            font-size: .64rem;
            margin: 0 0 auto 0
        }

        .top b span {
            color: #818181;
            font-weight: normal;
            font-size: .64rem
        }

        .top p span {
            font-weight: bold
        }

        .mid {
            text-align: left;
            padding: .8rem 0
        }

        .mid p {
            color: #8d8d8d
        }

        .red {
            color: red !important
        }

        .yellow {
            font-size: .52rem;
            color: #e69c1d !important
        }

        .border {
            border: .04rem solid transparent;
            border-radius: .16rem
        }

        .mid .df div.recharge {
            width: 4.12rem;
            height: 2.4rem;
            line-height: 2.4rem;
            font-size: .64rem;
            font-weight: bold;
            text-align: center;
            border: .04rem solid #b5b5b5;
            border-radius: .1rem
        }

        .mid div p {
            color: black
        }

        .mid .title {
            font-size: .62rem
        }

        .mid div span.green {
            display: none;
            bottom: -0.04rem;
            right: -0.04rem;
            width: 1.4rem;
            height: 1.4rem;
            background: url("https://img.fphdcdn.com/hall/paySelect.png") no-repeat 100% 100%;
            background-size: 1.1rem
        }

        .confirmBox {
            text-align: center;
            padding: 2rem .6rem .5rem .6rem
        }

        .confirmBox button {
            width: 13.8rem;
            height: 1.68rem;
            font-size: .64rem;
            border-radius: .26rem
        }

        .confirmBox b span {
            color: red
        }

        .confirmBox p {
            color: #aaaaab;
            font-size: .52rem;
            text-align: center
        }

        .confirm,
        .behalfPay,
        .aliPayH5,
        .aliPayP2P,
        .miniProgramPay,
        .wechatPay,
        .wechatH5Pay {
            margin: .6rem 0 .1rem 0;
            background: #1aad19;
            color: white;
            border: .02rem solid #1aad19
        }

        .confirm:active {
            background: #009300
        }

        .return:active {
            background: #f7f7f7
        }

        .confirm[disabled="disabled"] {
            background: #888;
            border-color: #888
        }

        .return {
            margin: .6rem 0;
            background: white;
            border: .02rem solid #dadada
        }

        .df {
            display: flex;
            display: -webkit-flex;
            flex-wrap: wrap;
            -webkit-flex-wrap: wrap
        }

        .active span {
            display: inline-block !important
        }

        .active {
            border: .04rem solid #1aad19 !important;
            color: #1aad19
        }

        .active .recharge {
            border: .04rem solid #1aad19 !important
        }

        .active p:nth-child(1) {
            background: #1aad19 !important;
            color: white !important
        }

        .active p:nth-child(2) {
            color: #1aad19
        }

        .back {
            font-size: .4rem !important
        }

        .back p:nth-child(1) {
            height: 1rem;
            line-height: 1rem;
            font-size: .52rem;
            background: #b5b5b5;
            color: #555;
            font-weight: normal
        }

        .optionBox {
            margin-top: .52rem;
            flex-wrap: wrap
        }

        .optionBox .border {
            margin: .2rem .52rem .2rem
        }

        .recharge p:nth-child(2) {
            height: 1.4rem;
            line-height: 1.4rem;
            font-size: .64rem;
            font-weight: bold
        }

        .contact {
            height: .6rem;
            color: #2286d3;
            text-align: center;
            font-size: .52rem;
            margin-bottom: 1.4rem
        }

        .bBox {
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            -webkit-flex-direction: column;
            font-size: .52rem
        }

        .bBox p {
            text-align: right;
            font-size: .52rem
        }

        .black {
            font-size: .72rem;
            font-weight: bold !important;
            color: black !important
        }

        .goodsName {
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            -webkit-flex-direction: column;
            width: 100% !important;
            color: #1aad19;
            border: .08rem solid #1aad19;
            border-radius: .2rem;
            padding: 1rem;
            margin: .52rem 0
        }

        .goodsName b {
            text-align: center;
            padding: 0 .2rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: .64rem
        }

        .goodsName b:nth-child(1) {
            margin-bottom: .6rem
        }

        .goodsName i {
            bottom: -0.04rem;
            right: -0.04rem;
            width: 1.4rem;
            height: 1.4rem;
            background: url("https://img.fphdcdn.com/hall/paySelect.png") no-repeat 100% 100%;
            background-size: 1rem
        }

        .box3 {
            background: white;
            padding: 1.2rem 0.6rem 0.8rem 0.6 rem；
        }

        .spanBox3 {
            display: block;
            margin: 1.8rem auto 0 auto;
            width: 3rem !important;
            height: 3rem !important;
            background-color: #1aad19;
            background: url("https://img.fphdcdn.com/hall/paySuccess.png") no-repeat 100% 100%
        }

        .payBox {
            padding: 0
        }

        .payBox h2 {
            color: #2ac845;
            font-size: 40.04rem;
            text-align: center;
            font-weight: normal;
            margin-bottom: 11rem
        }

        .payBox p {
            color: #606060;
            font-size: .64rem
        }

        .payBox b {
            display: block;
            text-align: center;
            margin-top: .76rem;
            font-size: 1.12rem
        }

        .payBox b span {
            position: relative;
            top: -0.36rem;
            font-size: .64rem;
            color: black;
            font-weight: normal
        }

        .Payable {
            font-size: .52rem;
            display: block;
            font-weight: normal;
            text-align: left
        }

        .Payable span {
            font-weight: bold;
            font-size: .84rem
        }

        .marginBottom {
            margin-bottom: .4rem
        }

        .box {
            margin-bottom: .16rem
        }

        .MyDialog .modal .diaolog {
            width: 80%;
            position: fixed;
            top: 50%;
            left: 50%;
            border-radius: .08rem;
            background: #fff;
            transform: translate(-50%, -50%);
            z-index: 510
        }

        .MyDialog .modal .cover {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #000;
            opacity: .6;
            z-index: 500
        }

        .MyDialog .modal .diaolog .content {
            padding: .6rem;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            align-items: center;
            -webkit-align-items: center
        }

        .MyDialog .modal .diaolog .content img {
            width: 70%
        }

        .MyDialog .modal .diaolog .content p {
            color: #999;
            font-size: .64rem;
            text-align: center;
            display: flex;
            display: -webkit-flex;
            margin: .08rem 0 ；
        }

        .MyDialog .modal .diaolog .content p img {
            position: relative;
            top: -0.1rem;
            width: 1rem;
            height: 1rem;
            margin-right: .6rem
        }

        .MyDialog .modal .diaolog .content .wechat {
            margin-top: inherit;
            margin-left: .3rem
        }

        .MyDialog .modal .diaolog .confirmButton {
            font-size: .64rem;
            color: red;
            text-align: center;
            padding: .4rem;
            border-top: .04rem solid #ddd;
        }

        .anotherPay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            background: rgba(58, 58, 58, 0.7);
            z-index: 50;
            width: 100%;
            height: 100%
        }

        .payDialog {
            position: absolute;
            width: 76%;
            height: 5rem;
            left: 12%;
            top: 10rem;
            margin: auto
        }

        .payDialog > .tittle {
            background: #fff;
            padding: 1rem 0;
            border-radius: .3rem .3rem 0 0
        }

        .payDialog > .tittle > p {
            margin-bottom: 5px;
            font-size: .66rem;
            color: #333
        }

        .payDialog > .tittle > p > span {
            color: #20a91d
        }

        .payDialog > .tittle > p:nth-last-child(1) {
            font-size: .58rem;
            color: #999
        }

        .payDialog > .btn {
            display: flex
        }

        .payDialog > .btn > div {
            text-align: center;
            width: 50%;
            padding: .5rem 0;
            color: #fff;
            font-size: .66rem;
            background: #c5c5c5;
            border-radius: 0 0 0 .3rem
        }

        .payDialog > .btn > .sure {
            background: #20a91d;
            border-radius: 0 0 .3rem 0
        }

        .share {
            position: fixed;
            top: 0;
            left: 0;
            z-index: 50;
            width: 100%;
            height: 100%;
            background: url("https://img.fphdcdn.com/hall/common/alipay/payShare.png");
            background-size: cover;
            display: none
        }

        .rechargeMask {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            display: none;
            background: rgba(0, 0, 0, 0.5);
        }

        .rechargeMask > .tipsTest {
            position: relative;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 80%;
            background-color: #fff;
            border-radius: .26rem;
            color: #5C5C5C;
            padding: 1rem .5rem;
            font-size: .7rem;
            text-align: justify;
            text-indent: 1.4rem;
            line-height: 1.1rem;
        }

        .rechargeMask > .tipsTest > img {
            width: 1.5rem;
            height: 1.5rem;
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
        }

        .offer {
            /* width: 100%;
            overflow: hidden;
            padding: 5px;
            color: #ee0707;
            background-color: #ffeab9; */
            width: 100%;
            overflow: hidden;
            padding: 5px;
            color: #ee0707;
            background-color: #ffeab9;
            height: 30px;
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .offer_info {
            overflow: hidden;
            height: 16px;
            margin: 0 5px;
            font-size: 14px;
        }

        .hide {
            display: none;
        }

        .layui-m-layerchild h3 {
            height: 55px;
            line-height: 55px;
        }

        .layui-m-layercont {
            padding: 0px 30px 50px;
            margin-top: 10px;
        }

        .ali_payMoney {
            color: #1A9BFF;
            font-size: 35px;
            text-align: center;
        }
    </style>
</head>

<body>

<div class="box">
    <div class="user_data" id="user_data"></div>
    <div class="offer"><img src="https://img.fphdcdn.com/hall/test/zeng.png" style="width: 20px;"/>
        <div class="offer_info">
        </div>
    </div>
    <div class="confirmBox">
        <b class="Payable">应付：<span id='shouldPay'></span></b>

        <div class="adapay hide channels" data-pay-type="10">
            <button class="wechatPay hide">微信支付</button>
            <button class="miniProgramPay hide">微信小程序</button>
            <button class="wechatH5Pay hide">H5微信支付</button>
        </div>
        <div class="kjtpay hide channels" data-pay-type="11">
            <button class="wechatPay hide">微信支付</button>
            <button class="miniProgramPay hide">微信小程序</button>
            <button class="wechatH5Pay hide">H5微信支付</button>
        </div>
        <div class="kjpay hide channels" data-pay-type="12">
            <button class="wechatPay hide">微信支付</button>
            <button class="miniProgramPay hide">微信小程序</button>
            <button class="wechatH5Pay hide">H5微信支付</button>
        </div>
        <div class="ikudot hide channels" data-pay-type="13">
            <button class="wechatPay hide">微信支付</button>
            <button class="miniProgramPay hide">微信小程序</button>
            <button class="wechatH5Pay hide">H5微信支付</button>
        </div>
        <button class="confirm" data-pay-type="1"></button>
        <button class="behalfPay hide">好友代付</button>
        <button class="aliPayH5">支付宝付款</button>
        <button class="aliPayP2P">好友代付-支付宝</button>
        <button class="return">返回</button>
        <p class="box" id='box_tips' style="display: none;">房卡在所有游戏内通用</p>
    </div>
    <!--代付弹框-->
    <div class="anotherPay">
        <div class="payDialog">
            <div class="tittle">
                <p>确认为 <span class="behalfPayUser">某某某(52336)</span>代付吗？ </p>
                <p>(付款前请务必和好友再次确认)</p>
            </div>
            <div class="btn">
                <div class="cancel">取消</div>
                <div class="sure">确认</div>
            </div>
        </div>
    </div>
    <!--分享遮罩层-->
    <div class="share"></div>
    <div class="contact">遇到问题？请联系客服</div>
    <!-- 游戏充值档（房卡和钻石），6元 12元 增加限制每天充值一次，每日零点重置可用次数 -->
    <div class="rechargeMask">
        <div class="tipsTest">
            6元每天仅可充值一次，请选择其他档位充值，每日0点重置当日充值次数
            <img src="https://img.fphdcdn.com/hall/game/gamehall/x.png" id="closeRechargeMask" alt="">
        </div>
    </div>
</div>

<script src="https://img.fphdcdn.com/hall/test/jquery.min.js"></script>
<script src="https://img.fphdcdn.com/hall/test/jquery.cookie.min.js"></script>
<script src="https://img.fphdcdn.com/hall/test/jquery.marquee.min.js"></script>
<script src="https://img.fphdcdn.com/hall/test/layer.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="https://alpha-locallife.fpwan.com/vconsole.min.js"></script>

<script>
    var payEnv = '';
    var vConsole = '';

    if (/(miniProgram)/i.test(navigator.userAgent)) {
        payEnv = 'xcx';
        if (location.host.indexOf('alpha') !== -1 || location.host.indexOf('beta') !== -1) {
            vConsole = new VConsole();
        }
        // vConsole = new VConsole();
    }
    // 新增ios安卓页面适配js
    !function () {
        function a() {
            var clientWidth = document.documentElement.clientWidth > 640 ? 640 : document.documentElement.clientWidth;
            document.documentElement.style.fontSize = clientWidth / 17 + "px";
            var div = document.createElement("div");
            div.style.width = "17rem";
            document.documentElement.style.fontSize = document.documentElement.style.fontSize.replace("px", "") * clientWidth / div.clientWidth + "px";
        }

        var b = null;
        window.addEventListener("resize", function () {
            clearTimeout(b), b = setTimeout(a, 300)
        }, !1), a()
    }(window);
    $(".contact").click(function () {
        window.location.href = order.hallPath + '?channelId=' + order.channelId + '#/chatKefu'
        window.location.href = '/gamehall/index.html?channelId=1029#/chatKefu?group='
    });

    var hosturl = location.host;
    var payApi = 'https://';
    var env = '';
    var indexParams = getQueryParams();
    // 小程序环境下使用小程序支付
    if (payEnv === 'xcx') {
        indexParams.payType = 7;
    }

    var wechatJsSdkChannelId = indexParams.channelId;
    if (hosturl.indexOf('alpha') !== -1 || hosturl.indexOf('127.0.0.1') !== -1) {
        env = 'alpha-';
    }
    if (hosturl.indexOf('beta') !== -1) {
        env = 'beta-';
    }
    payApi += env + 'pay2.fpwan.net';

    //api设置为本地
    //payApi = "http://" + window.location.host;
    payApi = JONO_HOST;

    $(".return").click(function () {
        payCancelRedirect();
    });

    var order = {};
    var payData, payUser = {};
    if (!indexParams.hasOwnProperty('redirectUrl') || !indexParams.redirectUrl) {
        indexParams.redirectUrl = document.referrer;
    }
    var behalfPay = '';
    if (indexParams.hasOwnProperty('behalfPay') && parseInt(indexParams.behalfPay) === 1) {
        behalfPay = 1;
        $(".behalfPay").hide();
    }

    // 获取微信JSSDK参数
    function wechatJsSdkInit() {
        $.ajax({
            type: "get",
            url: payApi + '/wechat/jsConfig?channelId=' + wechatJsSdkChannelId + '&jsApis=updateAppMessageShareData_updateTimelineShareData',
            dataType: "json",
            success: function (response) {
                var params = JSON.parse(response.data);
                wx.config(params);
                var shareUrl = window.location.href;
                if (!behalfPay) {
                    shareUrl += '&behalfPay=1';
                }
                var shareData = {
                    title: '好友代付申请',
                    link: shareUrl,
                    imgUrl: 'http://img.fphdcdn.com/behalfPay.png',
                    desc: '商品我已经选好了，是时候该你仗义疏财了，快去帮我支付吧。',
                };
                wx.ready(function () {
                    wx.updateAppMessageShareData(shareData);
                    wx.updateTimelineShareData(shareData);
                });
            },
            error: function () {
                alert('服务器访问异常');
                return false;
            }
        })
    }

    var paid;//游戏充值档（房卡和钻石）标识，6元 12元 增加限制每天充值一次，每日零点重置可用次数
    $.ajax({
        type: "post",
        url: payApi + '/pay/index',
        data: indexParams,
        dataType: "json",
        success: function (response) {
            payData = response.data ? response.data : {};
            if (response.code !== 0) {
                if (payData.hasOwnProperty('followUrl')) {
                    window.location.href = payData.followUrl;
                    return false;
                }
                alert(response.message);
                return false;
            }
            var payDataParams = payData.params;
            payUser = payData.user;
            order.payUrl = payData.payUrl;
            order.channelId = payData.channelId;
            order.userId = payUser.user_id;
            order.payId = payDataParams.payId;
            order.appId = payDataParams.appId;
            order.goodsId = payDataParams.goodsId;
            order.goodsName = payDataParams.goodsName;
            order.goodsNumber = payDataParams.goodsNumber;
            order.redirectUrl = payDataParams.redirectUrl;
            order.failRedirectUrl = payDataParams.failRedirectUrl;
            order.cancelRedirectUrl = payDataParams.cancelRedirectUrl;
            order.serverId = payDataParams.serverId;
            order.appState = payDataParams.appState;
            order.appOrderId = payDataParams.appOrderId;
            order.paiyouquanId = payDataParams.paiyouquanId;
            order.from = payDataParams.from;
            order.money = 0;
            order.taocanId = indexParams.hasOwnProperty('taocanId') ? indexParams.taocanId : 0;
            order.payType = payData.payType;
            order.remainFbi = payUser.user_fbi / 100;
            order.integralPay = payUser.user_wawa_quan_gift / 100;
            order.confirmObject = $('.confirm');//1--->购物 2--->到店
            order.pageType = payDataParams.pageType;
            order.hallWebUrl = payData.hallWebUrl;
            order.hallApiUrl = payData.hallApiUrl;
            order.hallPath = payData.hallPath;
            order.expendType = payData.expendType;
            order.previewSingleKey = payDataParams.previewSingleKey;

            // 微信支付隐藏代付功能
            if (!isWeiXin() || parseInt(order.payType) === 1 || parseInt(order.payType) === 10 || parseInt(order.payType) === 11) {
                $(".behalfPay").hide();
            } else {
                wechatJsSdkInit();
            }

            if (payData.pay_channel_id !== undefined && payData.pay_type_list !== undefined) {
                if (isWeiXin()) {
                    if (payData.is_pay_channel_wechat === 0) {
                        console.log('需要授权');
                        window.location.href = payData.wechat_oauth_url;
                    }
                } else {
                    $('.confirm').hide();
                }
                setPayStatus(payData.pay_channels);

            }
            var payId = parseInt(payDataParams.payId);
            $(".behalfPayUser").html(payUser.user_nickname + '(' + payUser.user_id + ')');
            var userDataHtmlStr =
                '<div class="top df">' +
                '<b>' + payUser.user_nickname + '<span>(' + payUser.user_id + ')</span></b>' +
                '<div class="bBox">' +
                '<p class="marginBottom">余额: ￥<span class="black" id="remainFbi">' + order.remainFbi + '</span></p>';
            if (payId === 103) {
                userDataHtmlStr += '<p>剩余 <span>' + payUser.user_fangka + '</span>张房卡</p>';
            }
            userDataHtmlStr += '</div></div><div class="mid"><p class="title">' + (payId === 106 ? "选择充值金额" : "选择支付金额") + '</p>';
            var taocanItemStr = '';
            var taocan = payData.taocan;
            switch (payId) {
                case 103:
                case 104:
                    userDataHtmlStr += '<div class="df optionBox">';
                    $(taocan).each(function (index, item) {
                        taocanItemStr = '';
                        taocanItemStr += '<div class="border ';
                        if (item.id == '3') {
                            taocanItemStr += 'active';
                            paid = item.paid
                        }
                        taocanItemStr += '"><div class="recharge back relative" taocanId=' + item.id + ' paid=' + item.paid + ' money="' + item.money + '" >';
                        taocanItemStr += '<p>' + item.title + '</p>';
                        taocanItemStr += '<p>' + item.name + '</p>';
                        taocanItemStr += '</div>';
                        taocanItemStr += '</div>\n';
                        userDataHtmlStr += taocanItemStr;
                    });
                    userDataHtmlStr += '</div>';
                    break;
                case 106:
                    // 充F币（余额）
                    userDataHtmlStr += '<div class="df optionBox">';
                    $(taocan).each(function (index, item) {
                        taocanItemStr = '';
                        taocanItemStr += '<div class="border ';
                        if (item.id == payData.currentTaocanId) {
                            taocanItemStr += 'active';
                        }
                        taocanItemStr += '"><div class="recharge relative" taocanId=' + item.id + ' money="' + item.money + '">';
                        taocanItemStr += item.name;
                        taocanItemStr += '<span class="absolute green"></span>';
                        taocanItemStr += '</div>';
                        taocanItemStr += '</div>\n';
                        userDataHtmlStr += taocanItemStr;
                    });
                    userDataHtmlStr += '</div>';
                    break;
                case 201:
                    $(taocan).each(function (index, item) {
                        taocanItemStr = '';
                        taocanItemStr += '<div class="goodsName relative active">';
                        taocanItemStr += '<b>' + item.name + '</b>';
                        taocanItemStr += '<b id="rechargeFbi" taocanId=' + item.id + ' money="' + item.money + '">' + item.money + '元</b>';
                        taocanItemStr += '<i class="absolute"></i>';
                        taocanItemStr += '<span class="absolute myicon-tick-checked spanBox2"></span>';
                        taocanItemStr += '</div>'
                        userDataHtmlStr += taocanItemStr;
                    });
                    break;
            }
            if (payId !== 106) {
                userDataHtmlStr += '<p class="yellow"> <span></span> 元</p>';
            }
            if (payId === 103) {
                $("#box_tips").show();
            }
            userDataHtmlStr += '</div>';
            $("#user_data").html(userDataHtmlStr);


            var money;
            var taocanId;
            if (payId === 201) {
                money = $('#rechargeFbi').attr("money");
                taocanId = $('#rechargeFbi').attr("taocanId");
            } else {
                money = $('.active .recharge').attr("money");
                taocanId = $('.active .recharge').attr("taocanId");
            }
            payClick(money, taocanId);
            browserIdJudge();
            $(".return").unbind("click").click(function () {
                payCancelRedirect();
            });

            if (indexParams.hasOwnProperty('autoPay') && parseInt(indexParams.autoPay) === 1) {
                $('.confirm').trigger('click');
            }
        },
        error: function () {
            alert('服务器访问异常');
            return false;
        }
    });
    var aliPayOfferChannels = [1045, 1048, 1010, 1013, 1014, 1015, 1018, 1023, 1033];
    if (aliPayOfferChannels.indexOf(Number(indexParams.channelId)) !== -1) {
        if (indexParams.hasOwnProperty('payId') && parseInt(indexParams.payId) == 103) {
            $(".offer_info").text("「支付宝付款额外赠送」 6元：10张+送1张 ，  30元：50+送10张 ， 120元：200+送80张， 多充多送！");
        } else if (indexParams.hasOwnProperty('payId') && parseInt(indexParams.payId) == 104) {
            $(".offer_info").text("「支付宝付款额外赠送」 6元：100+送10钻石 ，  30元：500+送100钻石 ，  120元：2000+送700钻石， 多充多送！");
        } else {
            $(".offer").hide();
        }
        $('.offer_info').marquee({
            duration: 10000,
            gap: 5,
            delayBeforeStart: -1000,
            direction: 'left',
            duplicated: true
        });
    } else {
        $(".offer").hide();
    }

    /**
     * 获取Url参数
     */
    function getQueryParams() {
        var url = location.search; //获取url中"?"符后的字串
        var params = new Object();
        if (url.indexOf("?") !== -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                params[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return params;
    }

    var shouldPay; // 应支付
    function payClick(money, taocanId) {
        var remainFbi = order.remainFbi;
        var expendType = order.expendType;
        var integralPay = order.integralPay;
        var strTips = "";
        var deduction; // 扣除金额
        var payButtonLabel = order.payId === 106 ? '充值' : '微信·支付';
        order.money = money;
        order.taocanId = taocanId;
        if (parseInt(order.payId) !== 106) {
            // 判断使用何种支付方式（1 F币  2 积分  3 F币+积分  4 单独金额）
            switch (parseInt(expendType)) {
                case 1:
                    strTips = "可使用余额支付";
                    shouldPay = remainFbi - money >= 0 ? 0 : money - remainFbi;
                    if (shouldPay === 0) {
                        payButtonLabel = "使用余额支付";
                        $(".aliPayP2P").hide();
                    }
                    deduction = remainFbi - money >= 0 ? money : remainFbi;
                    break;
                case 2:
                    strTips = "可使用积分支付";
                    shouldPay = integralPay - money >= 0 ? 0 : money - integralPay;
                    if (shouldPay === 0) {
                        payButtonLabel = "使用积分支付";
                    }
                    deduction = integralPay - money >= 0 ? money : integralPay;
                    break;
                case 3:
                    strTips = "可使用积分及余额支付";
                    // 优先扣积分
                    if (integralPay - money >= 0) {
                        shouldPay = 0;
                        payButtonLabel = "使用积分支付";
                        deduction = money;
                    } else {
                        if (remainFbi - (money - integralPay) >= 0) {
                            shouldPay = 0;
                            payButtonLabel = "使用积分及余额支付";
                            deduction = money;
                        } else {
                            shouldPay = money - integralPay - remainFbi;
                            deduction = integralPay + remainFbi;
                        }
                    }
                    break;
                case 4:
                    strTips = "可使用积分或余额支付";
                    shouldPay = order.money;
                    deduction = 0;
                    break;
                default:
                    shouldPay = remainFbi - money >= 0 ? 0 : money - remainFbi;
                    strTips = "可使用余额支付";
                    deduction = remainFbi - money >= 0 ? money : remainFbi;
                    break;
            }
            // 抵扣
            $(".yellow span").html(strTips + parseFloat(deduction).toFixed(2));
        } else {
            //  应付
            shouldPay = order.money;
        }
        $("#shouldPay").html('￥' + parseFloat(shouldPay).toFixed(2));
        order.confirmObject.html(payButtonLabel);
        return true;
    }

    $("body").on("click", ".confirm,.aliPayP2P,.aliPayH5,.wechatPay,.miniProgramPay,.wechatH5Pay", function () {
        if (paid == 1) {
            $(".rechargeMask").show()
        } else if (behalfPay === 1) {
            $('.anotherPay').show();
        } else {
            order.confirmObject.attr("disabled", "disabled");
            //如果是支付宝代付
            if ($(this).hasClass('aliPayP2P')) {
                order.payType = 1680;
            }
            if ($(this).hasClass('aliPayH5')) {
                order.payType = 1681;
            }
            //多通道默认支持自由微信支付
            if ($(this).hasClass('confirm')) {
                order.payType = 1;
            }
            order.payPlatform = undefined;
            if ($(this).hasClass('miniProgramPay')) {
                order.payPlatform = 'wechat_mini_program';
            }
            if ($(this).hasClass('wechatPay')) {
                order.payPlatform = 'wechat';
            }
            if ($(this).hasClass('wechatH5Pay')) {
                order.payPlatform = 'wechat_h5';
            }
            doOrder();
        }
    });
    $('.anotherPay').find('.cancel').click(function () {
        $('.anotherPay').hide();
    });
    $('.anotherPay').find('.sure').click(function () {
        order.confirmObject.attr("disabled", 'disabled');
        doOrder();
    });

    $(document).on('touchstart', '.recharge', function () {
        $(this).parent().addClass('active').siblings().removeClass('active');
        var money = $(this).attr("money");
        var taocanId = $(this).attr("taocanId");
        paid = $(this).attr("paid");
        payClick(money, taocanId);
    });

    //调用微信JS api 支付
    function onBridgeReady(data) {
        var jsParam = {
            "appId": data.appId,     // 公众号名称，由商户传入
            "timeStamp": data.timeStamp,         // 时间戳，自1970年以来的秒数
            "nonceStr": data.nonceStr, // 随机串
            "package": data.package,
            "signType": data.signType,         // 微信签名方式：
            "paySign": data.paySign // 微信签名
        };
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            jsParam,
            function (res) {
                WeixinJSBridge.log(res.err_msg);
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    paySuccessRedirect();
                } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                    alert('您取消了支付！');
                    payCancelRedirect();
                } else if (res.err_msg == "get_brand_wcpay_request:fail") {
                    alert('支付失败！');
                    payFailedRedirect();
                } else {
                    // 返回跳转到订单详情页面
                    alert('支付失败！');
                    payFailedRedirect();
                }
            }
        );
    }

    /**
     * 微信支付
     * @param  {[type]} data [description]
     * @return {[type]}      [description]
     */
    function callWxPay(data) {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
            }
        } else {
            this.onBridgeReady(data);
        }
    }

    /**
     * 支付宝h5付款 | 当面付-代付支付宝
     * @param  {[type]} data [description]
     * @return {[type]}      [description]
     */
    function callAliPay(data, aliPayType) {
        var paramsUrlString = data.payUrl;
        var requestObj = new Object();
        if (paramsUrlString.indexOf("?") != -1) {
            var str = paramsUrlString.slice(paramsUrlString.indexOf("?") + 1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                if (typeof requestObj[strs[i].split("=")[0]] == "undefined") requestObj[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        if (aliPayType == 'p2p') {
            requestObj.payWay = 'alipayp2p';
        } else if (aliPayType == 'h5') {
            requestObj.payWay = 'alipayh5';
        }
        $.ajax({
            type: "POST",
            url: payApi + "/fphdPay/index",
            data: requestObj,
            dataType: "json",
            beforeSend: function () {
                show();
            },
            complete: function () {
                // hide();    // 关闭遮罩层
            },
            success: function (response) {
                if (response.code !== 0) {
                    alert(response.message);
                    return false;
                }
                payData = response.data ? response.data : {};
                if (aliPayType == 'p2p') {
                    layer.open({
                        title: ['好友代付-支付宝扫码'],
                        content: '截图二维码或保存,发送朋友打开支付宝扫码付款即可.<img src="' + payData.qr_code_url + '" />',//如果qr_code_url为空则需要前端生成qr_code字串内容的二维码
                        btn: '关闭'
                    });
                    $(".layui-m-layercont").before('<h1 class="ali_payMoney">￥' + shouldPay + '</h1>');// 支付宝代付弹窗显示代付金额
                }
                if (aliPayType == 'h5') {
                    show();
                    var div = document.createElement('div');
                    div.innerHTML = payData;
                    document.body.appendChild(div);
                    if (isWeiXin()) {
                        window.location.href = location.origin + '/qrcode/alipayGuide.html?' + $("#alipaysubmit").serialize();
                    } else {
                        $("#alipaysubmit").submit();
                    }
                }
            },
            error: function (response) {
                console.error(response);
            }
        });
    }

    /**
     * 下单
     */
    function doOrder() {
        order.confirmObject.html("支付中 ······");
        order.goodsName = order.goodsName ? order.goodsName : '充值余额';
        var referer = window.location.href;
        if (payEnv === 'xcx') {
            var removeParams = ['openid', 'sign', 'time', 'sessionId', 'systemType'];
            $(removeParams).each(function (index, item) {
                referer = removeUrlParam(referer, item);
            })
        }
        var params = {
            money: order.money,
            userId: order.userId,
            host: LOCAL_HOST,
            paiyouquanId: order.paiyouquanId,
            taocanId: order.taocanId,
            order_source: browserID,
            previewSingleKey: order.previewSingleKey,
            behalfPay: behalfPay,
            referer: referer,
            payPlatform: order.payPlatform ? order.payPlatform : '',
            payType: order.payType == 1680 || order.payType == 1681 ? 4 : order.payType,//兼容收银台支付和支付宝代付
        };
        if (payEnv === 'xcx' && indexParams.hasOwnProperty('openid')) {
            params.xcxOpenId = indexParams.openid;
        }
        $.ajax({
            type: "POST",
            url: payApi + "/pay/makeOrder",
            data: params,
            dataType: "json",
            beforeSend: function () {
                show();       // 打开遮罩层
            },
            complete: function () {
                hide();    // 关闭遮罩层
            },
            success: function (response) {
                //自定义的
                order.confirmObject.removeAttr("disabled");
                order.confirmObject.html("支付");
                $('.payMoney').html(order.money);
                console.log(response);
                if (parseInt(response.code) !== 0) {
                    alert(response.message);
                } else {
                    // let orderId = response.data.orderId;
                    // window.location.href = payApi + "/pay/fphdPay?orderId=" + orderId;
                    //直接跳转到支付界面即可
                    jspost(response.data.url,response.data.data);
                }


                // order.confirmObject.removeAttr("disabled");
                // order.confirmObject.html("支付");
                // $('.payMoney').html(order.money);
                // console.log(response);
                // if (parseInt(response.code) !== 0) {
                //     if (payEnv === 'xcx' && parseInt(response.code) === -2) {
                //         var payLoginParams = {
                //             data: {
                //                 url: window.location.href + '&autoPay=1&taocanId=' + order.taocanId
                //             }
                //         };
                //         console.log('跳往授权', '/pages/pay/pay?action=payLogin&data=' + encodeURIComponent(JSON.stringify(payLoginParams)));
                //         wx.miniProgram.navigateTo({
                //             url: '/pages/pay/pay?action=payLogin&data=' + encodeURIComponent(JSON.stringify(payLoginParams))
                //         });
                //         return false;
                //     }
                //     alert(response.message);
                //     if (parseInt(response.code) === -3) {
                //         paySuccessRedirect();
                //     }
                //     return;
                // }
                // var data = response.data;
                // // 余额支付
                // if (data.hasOwnProperty('fbiPay') && parseInt(order.payType) !== 1680) {
                //     order.confirmObject.html("支付成功");
                //     alert('余额支付成功！');
                //     paySuccessRedirect();
                //     return;
                // }
                // // 积分支付
                // if (data.hasOwnProperty('integralPay')) {
                //     order.confirmObject.html("支付成功");
                //     alert('积分支付成功！');
                //     paySuccessRedirect();
                //     return;
                // }
                // switch (parseInt(order.payType)) {
                //     case 1:
                //         callWxPay($.parseJSON(data.params));
                //         break;
                //     case 2:
                //     case 4:
                //     case 5:
                //         var url = data.payUrl;
                //         window.location.href = url;
                //         break;
                //     case 3:
                //         var newwindow = window.open();
                //         newwindow.document.write(data);
                //         break;
                //     case 6:
                //         callWxPay(data.params);
                //         break;
                //     case 7:
                //         var payParams = $.parseJSON(data.params);
                //         payParams.redirect = {
                //             success: order.redirectUrl,
                //             fail: order.failRedirectUrl,
                //             cancel: order.cancelRedirectUrl
                //         };
                //         console.log('小程序支付参数', payParams);
                //         wx.miniProgram.navigateTo({
                //             url: '/pages/pay/pay?action=pay&data=' + encodeURIComponent(JSON.stringify(payParams))
                //         });
                //         break;
                //     case 10:
                //         if (data.hasOwnProperty('pay_url')) {
                //             window.location.href = data.pay_url;
                //         } else {
                //             callWxPay($.parseJSON(data.params));
                //         }
                //         break;
                //     case 11:
                //         callWxPay($.parseJSON(data.params));
                //         break;
                //     case 12:
                //         var url = data.hasOwnProperty('pay_url') ? data.pay_url : data.data.pay_url;
                //         window.location.href = url;
                //         break;
                //     case 13:
                //         if (data.hasOwnProperty('url')) {
                //             window.location.href = data.url;
                //         } else {
                //             callWxPay(data.pay_info);
                //         }
                //         break;
                //     case 1680:
                //         order.confirmObject.attr("disabled", "disabled");
                //         callAliPay(data, 'p2p');
                //         break;
                //     case 1681:
                //         callAliPay(data, 'h5');
                //         break;
                // }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                order.confirmObject.removeAttr("disabled");
                order.confirmObject.html("支付");
                alert('系统繁忙，请稍后再试');
                // 输出弹出jqXHR对象的信息
                console.log(jqXHR.responseText);
                console.log(jqXHR.status);
                console.log(jqXHR.readyState);
                console.log(jqXHR.statusText);
                // 记录其他两个参数的信息
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }



    function jspost(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post";
        //如需新打开窗口 form 的target属性要设置为'_blank'
        //temp.target = "_blank";
        temp.style.display = "none";
        for (var x in PARAMS) {
            var opt = document.createElement("textarea");
            opt.name = x;
            opt.value = PARAMS[x];
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
        return temp;
    }

    /*
    *  判断浏览器类型
    *  user：yangfang
    *  time: 2019.3.4
    */
    var browserID = 0; // 1为微信 2为闲聊 3为APP
    function browserIdJudge() {
        //window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
        var ua = window.navigator.userAgent.toLowerCase();
        //通过正则表达式匹配ua中是否含有MicroMessenger字符串
        console.log(ua.match(/MicroMessenger/i));
        console.log(ua.match(/XLMessenger/i));
        console.log(ua.match(/FPAPPMessenger/i));
        console.log(ua.match(/FPMessenger/i));
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            browserID = 1; // 微信
        } else if (ua.match(/XLMessenger/i) == 'xlmessenger') {
            browserID = 2; // 闲聊
        } else if (ua.match(/FPAPPMessenger/i) == 'fpappmessenger') {
            browserID = 3; // APP,旧版本标识
        } else if (ua.match(/FPMessenger/i) == 'fpmessenger') {
            browserID = 3; // APP,新版本标识
        }
    }

    // 显示遮罩层
    function show() {
        layer.open({
            type: 2,
            shadeClose: false		// 点击不允许关闭
        })
    }

    // 隐藏遮罩层
    function hide() {
        layer.closeAll();    // 关闭遮罩
    }

    // 显示代付弹框
    $(".behalfPay").click(function () {
        $(".share").show()
    })
    $(".share").click(function () {
        $(".share").hide()
    })
    //关闭充值档位提示弹窗
    $("#closeRechargeMask").click(function () {
        $(".rechargeMask").hide()
    })

    /**
     * 是否微信环境
     */
    function isWeiXin() {
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 支付失败跳转
     */
    function paySuccessRedirect() {
        window.location.href = order.redirectUrl;
    }

    /**
     * 支付失败跳转
     */
    function payFailedRedirect() {
        window.location.href = order.failRedirectUrl;
    }

    /**
     * 支付失败跳转
     */
    function payCancelRedirect() {
        window.location.href = order.cancelRedirectUrl;
    }

    /**
     * 移除url参数
     * @param url
     * @param param
     * @returns {string}
     */
    function removeUrlParam(url, param) {
        var arr = url.substr(url.indexOf('?') + 1).split('&');
        $(arr).each(function (index, item) {
            var arg = item.split('=')[0];
            if (arg === param) {
                arr.splice(index, 1);
            }
        })
        return url.split('?')[0] + '?' + arr.join('&')
    }

    //getRand([25,75]) return "0" or "1"
    /**
     * 概率 arr综合100
     * return index string
     */
    function getRand(arr) {
        var result = 0;
        var sum = arr.reduce(function (a, b) {
            return a + b;
        });
        for (index in arr) {
            rand = Math.round(Math.random() * (sum - 1) + 1);
            if (rand <= arr[index]) {
                return index;
            } else {
                sum -= arr[index];
            }
        }
        return result;
    }

    //比较当前时间是否在指定时间段内
    function isDuringDate(beginDateStr, endDateStr) {
        var nowData = new Date(),
            beginDate = new Date(beginDateStr),
            endDate = new Date(endDateStr);
        if (nowData >= beginDate && nowData <= endDate) {
            return true;
        }
        return false;
    }

    //多渠道显示
    function setPayStatus(payChannels) {
        if (payChannels.channel_status == 'fphd') {
            return false;
        }
        if (payChannels.channel_status == 'other') {
            $('.confirm').hide();
            //  showPayList(payChannels);
            // return false;
        }
        if (payChannels.payment_type == 'all') {
            console.log('通道一直:all');
            showPayList(payChannels);
            return false;
        } else if (payChannels.payment_type == 'time') {
            console.log('时间段显示');
            $(payChannels.payment_time).map(function (i, v) {
                if (isDuringDate(v[0], v[1]) == true) {
                    showPayList(payChannels);
                    console.log([v[0], v[1]]);
                }
            })
        } else if (payChannels.payment_type == 'random') {
            console.log('概率显示');
            var getRandValue = getRand([payChannels.payment_random, (100 - payChannels.payment_random)]);
            console.log(getRandValue);
            if (getRandValue == '0') {
                showPayList(payChannels);
                console.log(payChannels.payment_random);
            }
        }
    }

    //具体显示多渠道
    function showPayList(payChannels) {
        $.each(payChannels.channels, function (key, value) {
            if (value == true) {
                $('.channels').each(function (index, itme) {
                    if ($(itme).hasClass(key)) {
                        $(itme).removeClass('hide');
                        if (payChannels.platform_list[key].wechat == true) {
                            if (isWeiXin()) {
                                $(itme).find('.wechatPay').removeClass('hide');
                            }
                        }
                        if (payChannels.platform_list[key].wechat_mini_program == true) {
                            $(itme).find('.miniProgramPay').removeClass('hide');
                        }
                        if (payChannels.platform_list[key].wechat_h5 == true) {
                            $(itme).find('.wechatH5Pay').removeClass('hide');
                        }
                    }
                    ;
                });
            }
        });
    }
</script>
</body>

</html>